<!DOCTYPE HTML>
<html>
	<head>
		<title>带框拖拽</title>
		<meta charset="utf-8">
		<style>
			#div1{
				width:200px;
				height:200px;
				background: yellow;
				position: absolute;
			}
			.active{
				position:absolute;
				border:1px dashed black;

			}
		</style>
		<script>
			window.onload=function(){
				var oDiv=document.getElementById('div1');
				var disx=0;
				var disy=0;
				oDiv.onmousedown=function(ev){
					var oEvent=ev||event;
					disx=oEvent.clientX-oDiv.offsetLeft;
					disy=oEvent.clientY-oDiv.offsetTop;
					var oBox=document.createElement('div');
					oBox.className='active';
					oBox.style.width=oDiv.offsetWidth+'px';
					oBox.style.height=oDiv.offsetHeight+'px';
					document.body.appendChild(oBox);
					oBox.style.left=oDiv.offsetLeft-2+'px';
						oBox.style.top=oDiv.offsetTop-2+'px';
					document.onmousemove=function(ev){
						var oEvent=ev||event;
						var l=oEvent.clientX-disx;
						var t=oEvent.clientY-disy;
						oBox.style.left=l+'px';
						oBox.style.top=t+'px';
					};
					document.onmouseup=function(){
						document.onmousemove=null;
						document.onmouseup=null;
						oDiv.style.left=oBox.offsetLeft+'px';
						oDiv.style.top=oBox.offsetTop+'px';
						document.body.removeChild(oBox);
						
					};
					return false;
			}
			}
		</script>
	</head>
	<body>
		<div id="div1"></div>
	</body>
</html>